'use strict';

const Service = require('egg').Service;

class OrderService extends Service {
    //添加订单
    async addOrder(products,user,orderId) { //[{},{商品}]
        let create_time = new Date(); //提交订单的时间
        for(let i = 0;i<products.length;i++){
            //title 标题  money总价钱  num:数量  pid:商品的id
            let {title,price,num,pid} = products[i];
            await this.app.mysql.query('insert into orderlist (title,price,num,pid,create_timer,orderid,user) values (?,?,?,?,?,?,?)',[title,price,num,pid,create_time,orderId,user])
        }
    }

    async orderList(username){
        return this.app.mysql.query('select * from orderlist where user=?',[username])
    }
}

module.exports = OrderService;
